home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C12 / Comma.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  626 b   |  32 lines

  1. //: C12:Comma.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Overloading the ',' operator
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. class After {
  11. public:
  12.   const After& operator,(const After&) const {
  13.     cout << "After::operator,()" << endl;
  14.     return *this;
  15.   }
  16. };
  17.  
  18. class Before {};
  19.  
  20. Before& operator,(int, Before& b) {
  21.   cout << "Before::operator,()" << endl;
  22.   return b;
  23. }
  24.  
  25. int main() {
  26.   After a, b;
  27.   a, b;  // Operator comma called
  28.  
  29.   Before c;
  30.   1, c;  // Operator comma called
  31. } ///:~
  32.